package com.guigu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guigu.base.entity.TruckDriverLicense;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.base.mapper.TruckDriverLicenseMapper;
import com.guigu.base.service.TruckDriverLicenseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 司机驾驶证表 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-08
 */
@Service
public class TruckDriverLicenseServiceImpl extends ServiceImpl<TruckDriverLicenseMapper, TruckDriverLicense> implements TruckDriverLicenseService {

    /**
     * 保存司机驾驶证信息
     *
     * @param pdTruckDriverLicense 司机驾驶证信息
     * @return 司机驾驶证信息
     */
    @Override
    public TruckDriverLicense saveTruckDriverLicense(TruckDriverLicense pdTruckDriverLicense) {
        TruckDriverLicense driverLicense = baseMapper.selectOne(new LambdaQueryWrapper<TruckDriverLicense>().eq(TruckDriverLicense::getUserId, pdTruckDriverLicense.getUserId()));
        if (driverLicense == null) {

        } else {
            pdTruckDriverLicense.setId(driverLicense.getId());
        }
        saveOrUpdate(pdTruckDriverLicense);
        return pdTruckDriverLicense;
    }

    /**
     * 获取司机驾驶证信息
     *
     * @param userId 司机id
     * @return 司机驾驶证信息
     */
    @Override
    public TruckDriverLicense findOne(String userId) {
        LambdaQueryWrapper<TruckDriverLicense> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(userId)) {
            lambdaQueryWrapper.eq(TruckDriverLicense::getUserId, userId);
        }
        return getOne(lambdaQueryWrapper);
    }
}
